package _nio._socket._bio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @Author: huangya
 * @Date: 2020/5/29
 * @Description:
 */
public class TimeClient {

    public static void main(String[] args) {
        int port = 8080;
        if(args!=null && args.length>0){
            try {
                port = Integer.parseInt(args[0]);
            }catch (Exception e){

            }
        }
        Socket socket = null;
        PrintWriter out = null;
        BufferedReader br = null;
        try {
            socket = new Socket("127.0.0.1", port);
            br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            out = new PrintWriter(socket.getOutputStream(), true);
            out.println("query time order");
            System.out.println("query time order");
            String resp = br.readLine();
            System.out.println(resp);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(br!=null){
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                br=null;
            }
            if(out!=null){
                out.close();
                out=null;
            }
            if(socket!=null){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                socket=null;
            }
        }

    }
}
